import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:meiyunapp/component/colored_safe_area.dart';
import 'package:meiyunapp/page/order/order_list_page.dart';
import 'package:meiyunapp/widget/decor/aoc_decoration.dart';

class OrderPage extends StatefulWidget {
  const OrderPage({Key? key}) : super(key: key);

  @override
  _OrderPageState createState() => _OrderPageState();
}

class _OrderPageState extends State<OrderPage>
    with AutomaticKeepAliveClientMixin, SingleTickerProviderStateMixin {
  final List<Tab> _myTabs = <Tab>[
    const Tab(text: '全部订单'),
    const Tab(text: '待使用'),
  ];
  late TabController _tabController;

  @override
  void initState() {
    super.initState();
    _tabController = TabController(vsync: this, length: 2);
    _tabController.addListener(() {
      var index = _tabController.index;
      var previousIndex = _tabController.previousIndex;
    });
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return AnnotatedRegion(
      value: SystemUiOverlayStyle.dark,
      child: Scaffold(
        body: SafeArea(
          child: Column(
            children: [
              const SizedBox(),
              Padding(
                padding: const EdgeInsets.symmetric(horizontal: 11),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    const SizedBox(),
                    TabBar(
                      tabs: _myTabs,
                      controller: _tabController,
                      indicatorColor: Colors.black,
                      indicatorWeight: 2,
                      isScrollable: true,
                      labelStyle: const TextStyle(fontSize: 17),
                      //unselectedLabelStyle: const TextStyle(fontSize: 16),
                      labelPadding: const EdgeInsets.symmetric(horizontal: 20),
                      labelColor: Colors.deepOrange,
                      unselectedLabelColor: Colors.black26,
                      indicator: const AocDecoration(color: Colors.red),
                    ),
                    const Icon(Icons.message),
                  ],
                ),
              ),
              Expanded(
                child: TabBarView(
                  controller: _tabController,
                  children: [
                    OrderListPage(
                      state: 1,
                    ),
                    OrderListPage(
                      state: 2,
                    ),
                  ],
                ),
              )
            ],
          ),
        ),
      ),
    );
  }

  @override
  bool get wantKeepAlive => true;
}

class Page1 extends StatelessWidget {
  const Page1({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.yellow,
    );
  }
}

class Page2 extends StatelessWidget {
  const Page2({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.red,
    );
  }
}
